#include <UnitTest++.h>
#include "gList.h"
#include <string>
#include <stdio.h>
using namespace std;

struct GListFixture
{

    GListFixture()
    {
        this->myList = new GList<char>();
        myList->add('b');
        myList->add('t');
        myList->add('y');
        myList->add('d');
    }

    ~GListFixture()
    {
        delete this->myList;
        this->myList = 0;
    }

    GList<char>* myList;
};

TEST_FIXTURE(GListFixture, TestSize)
{
    CHECK_EQUAL(4, myList->size());
}

TEST_FIXTURE(GListFixture, TestGetElement)
{
    const char expectedData[] = "btyd";

    CHECK_EQUAL(expectedData[0], myList->get(0));
    CHECK_EQUAL(expectedData[1], myList->get(1));
    CHECK_EQUAL(expectedData[2], myList->get(2));
    CHECK_EQUAL(expectedData[3], myList->get(3));
}

TEST_FIXTURE(GListFixture, TestRemoveElementCheckingItsSize)
{
    int expectedSize = 3;

    myList->remove(2);

    CHECK_EQUAL(expectedSize, myList->size());
}

TEST_FIXTURE(GListFixture, TestRemoveTheFirstElement)
{
    const char expectedData[] = "tyd";

    myList->remove(0);

    CHECK_EQUAL(expectedData[0], myList->get(0));
    CHECK_EQUAL(expectedData[1], myList->get(1));
    CHECK_EQUAL(expectedData[2], myList->get(2));
}

TEST_FIXTURE(GListFixture, TestRemoveTheLastElement)
{
    const char expectedData[] = "bty";
    int expectedSize = 3;

    myList->remove(3);

    CHECK_EQUAL(expectedData[0], myList->get(0));
    CHECK_EQUAL(expectedData[1], myList->get(1));
    CHECK_EQUAL(expectedData[2], myList->get(2));
    CHECK_EQUAL(expectedSize, myList->size());
}

TEST(TestWithString)
{
    GList<string>* str = new GList<string > ();
    str->add("str1");
    str->add("str2");
    str->add("str3");
    str->add("blablabla");

    CHECK_EQUAL(4, str->size());
    CHECK_EQUAL("blablabla", str->get(3));
}